package com.smartleanx.module.hrm.service.examine.examineRecord;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.common.util.object.BeanUtils;
import com.smartleanx.framework.security.core.util.SecurityFrameworkUtils;
import com.smartleanx.module.hrm.controller.admin.examine.examineRecord.vo.ExamineRecordPageReqVO;
import com.smartleanx.module.hrm.controller.admin.examine.examineRecord.vo.ExamineRecordSaveReqVO;
import com.smartleanx.module.hrm.dal.dataobject.employee.EmployeeDO;
import com.smartleanx.module.hrm.dal.dataobject.examine.examineDimension.ExamineDimensionDO;
import com.smartleanx.module.hrm.dal.dataobject.examine.examineDimensionIndex.ExamineDimensionIndexDO;
import com.smartleanx.module.hrm.dal.dataobject.examine.examineRecord.ExamineRecordDO;
import com.smartleanx.module.hrm.dal.dataobject.examine.examineRecordRater.ExamineRecordRaterDO;
import com.smartleanx.module.hrm.dal.dataobject.examine.examineRecordRaterIndex.ExamineRecordRaterIndexDO;
import com.smartleanx.module.hrm.dal.dataobject.examine.examineResultConfig.ExamineResultConfigDO;
import com.smartleanx.module.hrm.dal.mysql.employee.EmployeeMapper;
import com.smartleanx.module.hrm.dal.mysql.examine.examinSon.ExamineMapper;
import com.smartleanx.module.hrm.dal.mysql.examine.examineDimension.ExamineDimensionMapper;
import com.smartleanx.module.hrm.dal.mysql.examine.examineDimensionIndex.ExamineDimensionIndexMapper;
import com.smartleanx.module.hrm.dal.mysql.examine.examineRecord.ExamineRecordMapper;
import com.smartleanx.module.hrm.dal.mysql.examine.examineRecordRater.ExamineRecordRaterMapper;
import com.smartleanx.module.hrm.dal.mysql.examine.examineRecordRaterIndex.ExamineRecordRaterIndexMapper;
import com.smartleanx.module.hrm.dal.mysql.examine.examineResultConfig.ExamineResultConfigMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 考核计划开始后生成记录 Service 实现类
 *
 * @author 
 */
@Service
@Validated
public class ExamineRecordServiceImpl implements ExamineRecordService {

    @Resource
    private ExamineRecordMapper examineRecordMapper;
    @Resource
    private ExamineRecordRaterIndexMapper examineRecordRaterIndexMapper;
    @Resource
    private ExamineMapper examineMapper;
    @Resource
    private ExamineDimensionMapper examineDimensionMapper;
    @Resource
    private ExamineDimensionIndexMapper examineDimensionIndexMapper;
    @Resource
    private EmployeeMapper employeeMapper;
    @Resource
    private ExamineRecordRaterMapper examineRecordRaterMapper;
    @Resource
    private ExamineResultConfigMapper examineResultConfigMapper;

    @Override
    public Integer createExamineRecord(ExamineRecordSaveReqVO createReqVO) {
        // 插入
        ExamineRecordDO examineRecord = BeanUtils.toBean(createReqVO, ExamineRecordDO.class);
        examineRecordMapper.insert(examineRecord);
        // 返回
        return examineRecord.getId();
    }

    @Override
    public void updateExamineRecord(ExamineRecordSaveReqVO updateReqVO) {
        // 校验存在
        validateExamineRecordExists(updateReqVO.getId());
        // 更新
        ExamineRecordDO updateObj = BeanUtils.toBean(updateReqVO, ExamineRecordDO.class);
        examineRecordMapper.updateById(updateObj);
    }

    @Override
    public void deleteExamineRecord(Integer id) {
        // 校验存在
        validateExamineRecordExists(id);
        // 删除
        examineRecordMapper.deleteById(id);
    }

    private void validateExamineRecordExists(Integer id) {
        if (examineRecordMapper.selectById(id) == null) {
//            throw exception(EXAMINE_RECORD_NOT_EXISTS);
        }
    }

    @Override
    public ExamineRecordDO getExamineRecord(Integer id) {
        return examineRecordMapper.selectById(id);
    }

    @Override
    public PageResult<ExamineRecordDO> getExamineRecordPage(ExamineRecordPageReqVO pageReqVO) {
        return examineRecordMapper.selectPage(pageReqVO);
    }




}